package com.weixin.controller;


import com.github.pagehelper.PageHelper;
import com.weixin.service.UserService;
import com.weixin.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private UserService userService;

    @GetMapping("/list")

    public Map list(@RequestParam(name="pageNumber", defaultValue = "0") Integer pageNumber, @RequestParam(name="pageSize", defaultValue = "0")Integer pageSize){
        Map map = new HashMap<>();
        map.put("total",userService.countByExample(null));
        PageHelper.startPage(pageNumber,pageSize);



        map.put("rows",userService.selectAll());
        return map;
    }
    @PostMapping("/remove/{id}")
    public R remove(@PathVariable Integer id) {
        int i = userService.deleteByPrimaryKey(id);
        if(i>0){
            //删除成功
            return R.ok("删除成功");
        }else{
            //删除失败
            return R.error("删除失败");
        }
    }
}
